package com.newhonor.server.config;

import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * Redis配置类
 *
 * @Author newhonor
 * @Date 2021/2/21 22:54
 * @Version 1.0
 **/
public class RedisConfig {

    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory){
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        //String类型key序列化
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //String类型value序列化
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        //Hash类型ke序列化
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());;
        //Hash类型value序列化
        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());;
        redisTemplate.setConnectionFactory(connectionFactory);
        return redisTemplate;
    }
}
